# 
# Copyright 1999 by Digi International (www.digi.com)
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
#
#	Main Makefile for PCI DataFire RAS/AccelePort RAS/AccelePort 2000 driver
#	for Linux
#
#	$Id: Makefile50,v 1.2 2022/11/02 16:19:04 dupdegra Exp $
#


# To make correct module for
#   kernels 2.5 <= k < 5.3
#     make -C path/to/kernel/src SUBDIRS=$PWD modules
#   kernels 5.3 <= k
#     make -C path/to/kernel/src M=$PWD modules

prefix = @prefix@
datarootdir = @datarootdir@

ifndef MYPWD   
MYPWD = $(shell pwd)
endif

MODDIR = $(RPM_BUILD_ROOT)@MODDIR@/misc

LSMOD = @LSMOD@
RMMOD = @RMMOD@
INSMOD = @INSMOD@

# Grab version and other important stuff
include ${MYPWD}/../../Makefile.inc

MANDIR=@mandir@

ifndef MYMANDIR
MYMANDIR = ${MANDIR}
endif

MODULE= dgrp.ko


# Send in some extra things...
EXTRA_CFLAGS += -I${MYPWD} -I${MYPWD}/include -I${MYPWD}/../../commoninc \
	-DDIGI_VERSION=\"$(TRUE_VERSION)\" -DDGRP_TRACER

# the change from PDE_DATA -> pde_data is properly a kernel rev detection,
# but RHEL defeated us by backporting it.  So; we flail and have to grep to
# relevant include file to see if this is that, and make our own define flag
ifneq ($(shell grep '^static inline void \*pde_data' @KERNEL_HEADERS@/include/linux/proc_fs.h),)
EXTRA_CFLAGS += -DLOW_PDE_DATA
endif

# Conform to correct kbuild conventions...
obj-m += dgrp.o
dgrp-objs := 	dgrp_common.o dgrp_dpa_ops.o dgrp_driver.o \
		dgrp_mon_ops.o  dgrp_net_ops.o dgrp_ports_ops.o \
		dgrp_proc.o dgrp_specproc.o dgrp_tty.o dgrp_sysfs.o


all: build


build:
	make -C @KERNEL_HEADERS@ M=$$PWD modules MYPWD=${MYPWD} MYMANDIR=${MYMANDIR}

install:
	install -m 0755 -d $(MODDIR)
	install -m 0644 $(MODULE) $(MODDIR)
	install -d  $(RPM_BUILD_ROOT)$(MYMANDIR)/man8
	install -m 644 dgrp.man $(RPM_BUILD_ROOT)$(MYMANDIR)/man8/dgrp.8


uninstall:
	-rm -f $(MODDIR)/$(MODULE)
	-rm -f $(RPM_BUILD_ROOT)$(MYMANDIR)/man8/dgrp.8*


clobber: clean
	rm -rf Makefile


clean:
	rm -f *.o
	rm -f *.ko
	rm -f dgrp.mod.c
	rm -f .*.cmd
	rm -rf .tmp_versions
	-rm -f *.i *.s
	rm -rf *.symvers
	rm -rf modules.order
	rm -rf Module.markers


.PHONY: build all install uninstall postinstall preuninstall prep

